﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WssServer
{
    /// <summary>
    /// 订单
    /// </summary>
    public class Order
    {
        public Order()
        {

        }
        [DisplayName("订单号"), Browsable(true), Description("Key")]
        public string OrderID { get; set; }
        [DisplayName("乘客")]
        public string Passenger { get; set; }
        [DisplayName("接单司机")]
        public string Driver { get; set; }
        [DisplayName("推送司机")]
        public string PushDrivers { get; set; }
        [DisplayName("出发地址")]
        public string StartAddress { get; set; }
        [DisplayName("出发城市")]
        public string StartCity { get; set; }
        [DisplayName("目的地址")]
        public string EndAddress { get; set; }
        [DisplayName("目的城市")]
        public string EndCity { get; set; }

        [Browsable(false), DisplayName("出发纬度")]
        public double StartLatitude { get; set; }
        [Browsable(false), DisplayName("出发经度")]
        public double StartLongitude { get; set; }
        [Browsable(false), DisplayName("目的纬度")]
        public double EndLatitude { get; set; }
        [Browsable(false), DisplayName("目的经度")]
        public double EndLongitude { get; set; }

        [Browsable(false), DisplayName("预计车费")]
        public float EstimatedCost { get; set; }
        [Browsable(false), DisplayName("预计行程")]
        public float EstimatedDistance { get; set; }

        [DisplayName("车费")]
        public float RealCost { get; set; }
        [DisplayName("行程")]
        public float RealDistance { get; set; }
        [DisplayName("支付")]
        public int IsPay { get; set; }

        [DisplayName("订单状态")]
        public int OrderState { get; set; }
        [Browsable(false), DisplayName("订单类型")]
        public int OrderType { get; set; }



        [DisplayName("抢单时间")]
        public string StartDate { get; set; }
        [Browsable(false), DisplayName("计费时间")]
        public string StartCountDate { get; set; }
        [Browsable(false), DisplayName("结束时间")]
        public string EndDate { get; set; }

        [DisplayName("车辆信息")]
        public string CarInfo { get; set; }
        /// <summary>
        /// 用于顺风车，将多个订单号合并成一个顺风车单号
        /// </summary>
        [Browsable(false), DisplayName("合并单号")]
        public string ComboOrderID { get; set; }

        [Browsable(false), DisplayName("取消人")]
        public string CancelUser { get; set; }
        [Browsable(false), DisplayName("取消原因")]
        public string CancelRemark { get; set; }
        [Browsable(false), DisplayName("往返")]
        public bool IsReturn { get; set; } = false;
        [Browsable(false), DisplayName("加价")]
        public float AddMoney { get; set; } = 0;

        //预约时间
        [DisplayName("预约时间")]
        public string Bespoke { get; set; }
        //实际乘车人（代叫）
        [DisplayName("实际乘车")]
        public string RealPassenger { get; set; }
        /// <summary>
        /// 微信端模板消息的fromID(预约后通知乘客的需要)
        /// </summary>
        [Browsable(false)]
        public string FormID { get; set; }
        /// <summary>
        /// 顺风车匹配度
        /// </summary>
        [Browsable(false)]
        public int SfcPpd { get; set; } = 0;
        /// <summary>
        /// 顺风车人数
        /// </summary>
        [Browsable(false)]
        public int SfcRs { get; set; } = 1;

        #region 方法
        /// <summary>
        /// 获取消息的扩展消息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> GetExtras()
        {
            Dictionary<String, object> extras = new Dictionary<string, object>();
            extras.Add(nameof(OrderID), OrderID);
            extras.Add(nameof(Passenger), Passenger);
            extras.Add(nameof(StartAddress), StartAddress);
            extras.Add(nameof(StartCity), StartCity);
            extras.Add(nameof(EndAddress), EndAddress);
            extras.Add(nameof(EndCity), EndCity);

            extras.Add(nameof(StartLatitude), StartLatitude);
            extras.Add(nameof(StartLongitude), StartLongitude);
            extras.Add(nameof(EndLatitude), EndLatitude);
            extras.Add(nameof(EndLongitude), EndLongitude);

            extras.Add(nameof(EstimatedCost), EstimatedCost);
            extras.Add(nameof(EstimatedDistance), EstimatedDistance);

            extras.Add(nameof(StartDate), StartDate);
            extras.Add(nameof(OrderType), (int)OrderType);
            extras.Add(nameof(AddMoney), AddMoney);

            return extras;
        }
        /// <summary>
        /// 获取消息内容
        /// </summary>
        /// <returns></returns>
        public string GetMsgContent()
        {
            string msg = "";
            if (StartLatitude > 0)
            {
                msg = $"{OrderType.ToString()}：从{StartAddress}到{EndAddress},行程{Math.Round(EstimatedDistance / 1000, 2)}公里，{EstimatedCost}元";
            }
            else msg = $"{OrderType.ToString()}：从{StartAddress}到{EndAddress}";
            if (AddMoney > 0)
                msg = $"加价{AddMoney}元 " + msg;
            if (string.IsNullOrEmpty(Bespoke) == false)
                msg = $"预约{Bespoke};" + msg;
            return msg;
        }
        #endregion

    }

}
